|
mruby 4.0.0
mruby is the lightweight implementation of the Ruby language
|
Symbols in mruby C source code is represented by mrb_sym which is alias of uint32_t. Lower 30 bits are used for symbols so that higher 2 bits can be used as flags, e.g. struct mt_elem in class.c.
We provide following C API for symbols.
Get a symbol from a string.
Get a symbol from a NULL terminated (C) string.
Get a symbol from a Ruby string object.
Get a symbol from a C string literal. The second argument should be a C string literal, otherwise you will get a compilation error. It does not copy C string given the fact it's a literal.
Get a symbol from a string if the string has been already registered as a symbol, otherwise return 0. We also provide variants mrb_intern_check_str() (from Ruby string) and mrb_intern_check_cstr() (from C string).
Get a string representation of a symbol as a C string.
Get a string representation of a symbol, and its length.
To save RAM, mruby can use compile-time allocation of some symbols. You can use following macros to get preallocated symbols by including mruby/presym.h header.
For MRB_OPSYM(), specify the names corresponding to operators (see MRuby::Presym::OPERATORS in lib/mruby/presym.rb for the names that can be specified for it). Other than that, describe only word characters excluding leading and ending punctuation.
These macros are converted to static symbol IDs at compile time. The _2 suffix variants (e.g., MRB_SYM_2) are kept for backward compatibility only; they accept an explicit mrb_state* parameter but ignore it. New code should use the standard macros above.